// <editor-fold defaultstate="collapsed" desc="GNU GPLv3 Header">
/*
 * File:   FormatChunkWaveFile.java
 *
 * Copyright (C) 2013 Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * Copyright (C) 2013 David Megias Jimenez <dmegias@uoc.edu>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// </editor-fold>

package readwave;

// <editor-fold defaultstate="collapsed" desc="imports">
import java.io.DataInputStream;
import java.io.IOException;
// </editor-fold>

/**
 *
 * @author Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * @version 1.0
 * @since 2013-08-04
 */
class FormatChunkWaveFile extends GenericChunkWaveFile {

    short wFormatTag;
    short wChannels;
    int dwSamplesPerSec;
    int dwAvgBytesPerSec;
    short wBlockAlign;
    short wBitsPerSample;

    /**
     *
     * @param dis
     *
     * @since 2013-08-04
     */
    FormatChunkWaveFile(DataInputStream dis) throws IOException {
        super(12);
        readID(dis);
        readSize(dis);
        readWFormatTag(dis);
        readWChannels(dis);
        readDWSamplesPerSec(dis);
        readDWAvgBytesPerSec(dis);
        readWBlockAlign(dis);
        readWBitsPerSample(dis);
    }

    /**
     *
     * @param dis
     *
     * @since 2013-08-04
     */
    private void readWFormatTag(DataInputStream dis) throws IOException {
        wFormatTag = readShortLE(dis);
        System.out.println("wFormatTag : " + wFormatTag);
    }

    /**
     *
     * @param dis
     *
     * @since 2013-08-04
     */
    private void readWChannels(DataInputStream dis) throws IOException {
        wChannels = readShortLE(dis);
        System.out.println("wChannels : " + wChannels);
    }

    /**
     *
     * @param dis
     *
     * @since 2013-08-04
     */
    private void readDWSamplesPerSec(DataInputStream dis) throws IOException {
        dwSamplesPerSec = readLongLE(dis);
        System.out.println("dwSamplesPerSec : " + dwSamplesPerSec);
    }

    /**
     *
     * @param dis
     *
     * @since 2013-08-04
     */
    private void readDWAvgBytesPerSec(DataInputStream dis) throws IOException {
        dwAvgBytesPerSec = readLongLE(dis);
        System.out.println("dwAvgBytesPerSec : " + dwAvgBytesPerSec);
    }

    /**
     *
     * @param dis
     *
     * @since 2013-08-04
     */
    private void readWBlockAlign(DataInputStream dis) throws IOException {
        wBlockAlign = readShortLE(dis);
        System.out.println("wBlockAlign : " + wBlockAlign);
    }

    /**
     *
     * @param dis
     *
     * @since 2013-08-04
     */
    private void readWBitsPerSample(DataInputStream dis) throws IOException {
        wBitsPerSample = readShortLE(dis);
        System.out.println("wBitsPerSample : " + wBitsPerSample);
    }

    /**
     *
     * @param dis
     * @return the bits per sample
     * @see int
     *
     * @since 2013-08-04
     */
    public short getWBitsPerSample(){
        return wBitsPerSample;
    }
}
